package com.jd.finance.core.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.jd.finance.core.mapper.AboutInfoMapper;
import com.jd.finance.core.pojo.entity.AboutInfo;
import com.jd.finance.core.service.AboutInfoService;
import com.jd.finance.core.service.OpreateLogService;
import com.jd.finance.result.BaseResult;
import com.jd.finance.util.IpUtil;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

/**
 * <p>
 * 关于我们信息表 服务实现类
 * </p>
 *
 * @author LiQingBo
 * @since 2022-05-19
 */
@Service
public class AboutInfoServiceImpl extends ServiceImpl<AboutInfoMapper, AboutInfo> implements AboutInfoService {

    @Resource
    private AboutInfoMapper aboutInfoMapper;

    @Autowired
    private OpreateLogService opreateLogService;

    @Resource
    private AdminUtilsServiceImpl adminUtilsServiceimpl;

    /**
     * 修改关于我们
     *
     * @param uid     用户id
     * @param aboutUs 内容
     * @param request
     * @return
     */
    @Override
    public BaseResult updateAppAboutUs(Integer uid, String aboutUs, HttpServletRequest request) {
        if (uid == null) {
            log.error("id为空!");
            return BaseResult.error().message("id为空");
        }
        if (!adminUtilsServiceimpl.isInformation(uid)) {
            log.error("当前登录用户不是信息管理员账户");
            return BaseResult.error().message("当前登录用户不是信息管理员账户");
        }
        if (StringUtils.isBlank(aboutUs)) {
            log.error("内容为空");
            return BaseResult.error().message("内容为空");
        }
        AboutInfo aboutInfo = new AboutInfo();
        aboutInfo.setAboutUs(aboutUs);
        int i = aboutInfoMapper.update(aboutInfo, null);
        if (i >= 1) {
            return BaseResult.ok().data("neirong", 1);
        }
        boolean add = opreateLogService.add(uid, "修改", "修改关于我们", IpUtil.getIpAddr(request));
        if (!add) {
            log.error("添加操作日志失败!");
        }
        return BaseResult.ok().data("neirong", 0);
    }
}
